package com.sisy.controller;

import com.sisy.poji.AccountDO;
import com.sisy.poji.OrderCreateDTO;
import com.sisy.poji.StorageDO;
import com.sisy.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author EJ
 * @date 2021-06-11 15:38
 */
@Controller
@ResponseBody
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/order/create")
    public String orderCreate(@RequestBody OrderCreateDTO orderCreateDTO) {
        log.info("/order/create");
        orderService.createOrder(orderCreateDTO);
        return "SUCCESS";
    }

    @GetMapping("/order/{id}")
    public String getOrder(@PathVariable String id) {
        log.info("/order/{id}");
        return "Building ...";
    }

    @GetMapping("/account/{userId}")
    public AccountDO getAccount(@PathVariable String userId) {
        log.info("/account/{userId}");
        return orderService.getAccountByUserId(userId);
    }

    @GetMapping("/account/update/{userId}")
    public AccountDO getAccountUpdate(@PathVariable String userId) {
        log.info("/account/update/{userId}");
        return orderService.getAccountByUserIdUpdate(userId);
    }

    @GetMapping("/storage/{code}")
    public StorageDO getStorageByCode(@PathVariable String code){
        log.info("/storage/{code}");
        return orderService.getStorageByCommodityCode(code);
    }

    @GetMapping("/storage/update/{code}")
    public StorageDO getStorageByCodeUpdate(@PathVariable String code){
        log.info("/storage/update/{code}");
        return orderService.getStorageByCommodityCodeUpdate(code);
    }
}
